package de.fhaugsburg.games.boardgames.connect4;

import de.fhaugsburg.games.boardgames.Board;
import de.fhaugsburg.games.boardgames.GridPoint;
import de.fhaugsburg.games.boardgames.exceptions.GameException;

/**
 * A specific board for the boardgame Connect4. Connect4Board extends the class
 * Board.
 * 
 * @author r4smus
 * 
 */
public class Connect4Board extends Board<BinaryPiece, Object> {

	public Connect4Board(int rows, int columns) {
		super(rows, columns);
		// TODO Auto-generated constructor stub
	}

	/**
	 * put a piece in the first empty row (begins with the highest row) from a
	 * specific column.
	 * 
	 * @param piece
	 * @param column
	 * @return the row in which the piece was placed.
	 * @throws GameException 
	 */
	public int putPiece(BinaryPiece piece, int column) throws GameException {
		int currentRow = 0;
		for (int row = getHeight() - 1; row >= 0; row--) {
			if (isEmpty(new GridPoint(row,column))) {
				putPiece(piece, new GridPoint(row,column));
				currentRow = row;
				break;
			}

		}
		return currentRow;
	}

	/**
	 * Overrides the movePiece method from board and throw a
	 * UnsupportedOperationException, because this method will not be needed in
	 * Connect4.
	 */
	public void movePiece(int fromRow, int fromColumn, int toRow, int toColumn) {
		throw new UnsupportedOperationException();
	}

}
